package com.lagou.dao;


import com.lagou.domin.Admin;
import com.lagou.domin.Student;
import com.lagou.util.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.SQLException;

public class AdminDao {
    QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
    public boolean checkAdmin(Admin admin) {
        String sql = "select count(*) from admins where username = ? and password = ?";
        try {
            Long count = qr.query(sql, new ScalarHandler<Long>(), admin.getUsername(), admin.getPassword());
            return count > 0;
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }

    public void addStudent(Student student){
        String sql = "insert into students (id, name, sex, birth) values (?, ?, ?, ?)";
        try {
            qr.update(sql, student.getId(), student.getName(), student.getSex(), student.getBirth());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
